package org.hope.lee.service;

import org.hope.lee.dao.UserMapper;
import org.hope.lee.model.User;
import org.hope.lee.utils.DBContextHolder;
import org.hope.lee.utils.DBType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 *   
 *  @ProjectName: separated-read-write 
 *  @Description:
 *  @author: lisen
 *  @date: 2017/12/10  
 */
@Service("userService")
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    public void addUser(User user) {
        DBContextHolder.setDBType(DBType.DB_TYPE_MASTER);
        userMapper.insert(user);
    }

    public User getUserById(int id) {
        DBContextHolder.setDBType(DBType.DB_TYPE_SLAVE_ONE);
        return userMapper.selectOne(id);
    }
}
